#include "ObstacleAgentMgr.h"

void CObstacleAgentMgr::Init(dtTileCache* pTileCache, dtNavMesh *pNav)
{
	m_tileCache = pTileCache;
	m_nav = pNav;
}

bool CObstacleAgentMgr::AddAgent(MONSTER_ID idx, const float* pos, float radius, float height)
{
	dtObstacleRef ref;
	dtStatus status = m_tileCache->addObstacle(pos, radius, height, &ref);
	if (dtStatusSucceed(status))
	{
		m_MapObstacle.insert(std::make_pair(idx, ref));
		m_tileCache->update(50, m_nav);
		return true;
	}
	return false;
}

bool CObstacleAgentMgr::RemoveAgent(MONSTER_ID idx)
{
	auto iter = m_MapObstacle.find(idx);
	if (iter != m_MapObstacle.end())
	{
		dtStatus status = m_tileCache->removeObstacle(iter->second);
		if (dtStatusSucceed(status))
		{
			m_MapObstacle.erase(iter);
			m_tileCache->update(50, m_nav);
			return true;
		}	
	}
	return false;
}


